#include <iostream>
#include <unordered_set>
using namespace std;
using ll=long long;
const int N=1e6+10;
int f1[N],f2[N];
int sub[N];
int a[N];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	unordered_set<int> has;
	for(int i=n;i>=1;i--)
	{
		
		sub[i]=has.size();
		if(has.count(a[i]))
		{
			sub[i]--;
		}
		f2[a[i]]++;
		if(f2[a[i]]>=2)
		{
			has.insert(a[i]);
		}
	}
	ll ret=0;
	for(int i=1;i<=n;i++)
	{
//		cout<<a[i]<<' '<<sub[i]<<endl;
		if(f1[a[i]]==0)
			ret+=sub[i];
		f1[a[i]]++;
	}
	cout<<ret<<endl;
	return 0;
}
